﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AuctionSite.App_Code.Modelos;
using AuctionSite.App_Code.DAL;
using AuctionSite.App_Code.BLL;
using System.Globalization;
using System.Web.Security;

namespace AuctionSite
{
    public partial class Cadastro : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void btnCadastrar_Click(object sender, EventArgs e)
        {
            if (IsPostBack)
            {

                #region Cria Usuário

                string formato = "yyyy-MM-dd HH:mm:ss:fff";
                string dataString = DateTime.Now.ToString(formato);
                DateTime conversaoBD = DateTime.ParseExact(dataString, formato, CultureInfo.InvariantCulture);

                string senha = FormsAuthentication.HashPasswordForStoringInConfigFile(txtSenha.Text.ToString(), "sha1");

                

                Usuario u = new Usuario(
                        txtNome.Text.ToString(),
                        txtApelido.Text.ToString(),
                        txtTel.Text.ToString(),
                        txtCel.Text.ToString(),
                        txtEnd.Text.ToString(),
                        txtCpf.Text.ToString(),
                        txtEmail.Text.ToString(),
                        senha,
                        "T",
                        conversaoBD
                        );
                #endregion

                UsuarioBLL bll = new UsuarioBLL();
                bool testa = bll.Incluir(u);

                if (testa)
                {
                    Response.Write(
                        "<script type='text/javascript'>" +
                            "alert ('Cadastro Efetuado com Sucesso!');" +
                            "window.location.href='Login.aspx';" +
                         "</script>"
                    );
                }
                //else
                //{
                //    Response.Write(
                //        "<script type='text/javascript'>" +
                //            "alert ('Erro no Cadastro! Tente Novamente em instantes!');" +
                //            "window.location.href='Login.aspx';" +
                //         "</script>"
                //    );
                //}
            }
        }
    }
}